﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nhLib.Extensions;

public class TEntityExtension
{
    public static bool IsModifiedButNotSaved<TEntity>(DbContext context, TEntity entity) where TEntity : class
    {
        var entry = context.Entry(entity);
        return entry.State == EntityState.Modified && !context.ChangeTracker.Entries().Any(e => e.State == EntityState.Added || e.State == EntityState.Deleted);
    }
}
